//
//  RBShopIntroVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/22.
//

#import "RBShopIntroVC.h"
#import "UIViewController+RBAdd.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RanTool.h"
#import "RBPager.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "RBNavigationBar.h"
#import "RBGradientView.h"
#import "RBShopDetailResponse.h"

@interface RBShopIntroVC ()

@property(nonatomic, strong)UIScrollView *scrollView;
@property(nonatomic, strong)RBNavigationBar *navigationBar;

@property(nonatomic, strong) RBShopDetailResponse *response;

@end

@implementation RBShopIntroVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self getData];
}

#pragma mark - Private

- (void)setup
{
    self.statusBarStyle = UIStatusBarStyleLightContent;
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
    [self.view view_addView:[RanTool imgViewWithMode:2 radius:0 imgName:@"shopDetailBg"] withHeight:Zoom(363) width:kRBMainScreenWidth top:0 bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
    self.scrollView.hidden = NO;
    self.navigationBar.hidden = NO;
}

- (void)fillData
{
    [self.scrollView rbSetContentWidth:kRBMainScreenWidth];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool imgViewWithMode:2 radius:Zoom(3) imgName:self.response.data.logo] withHeight:Zoom(36) width:Zoom(36) top:0 bottom:0 left:0 right:0 centerY:0];
        [view h_view_addView:({
            UIView *view = UIView.new;
            
            UILabel *titleL = [RanTool labelWithFontSize:Zoom(15) weight:2 color:UIColor.whiteColor align:0 text:self.response.data.store_name];
            [view addSubview:titleL];
            [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
            }];
            
            UILabel *desL = [RanTool labelWithFontSize:Zoom(12) weight:1 color:UIColor.whiteColor align:0 text:[NSString stringWithFormat:@"开店时间：%@  |  粉丝数%@",self.response.data.kaidian_time,self.response.data.fensi]];
            desL.alpha = 0.8;
            [view addSubview:desL];
            [desL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.bottom.right.mas_equalTo(0);
            }];
            
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
        [view h_view_addView:({
            RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#70A1FF"], [UIColor colorWithHexString:@"#2663D9"]] locations:nil vertical:NO];
            [view rbSetCornerRadius:Zoom(12)];
            [view view_addView:({
                UILabel *view = UILabel.new;
                [view rbAddTapGesWithTarget:self action:@selector(collectBtnTapped)];
                view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                    UIFont *font = [UIFont systemFontOfSize:Zoom(12)];
                    [maker addAttributeStringWithImage:[UIImage imageNamed:self.response.data.is_shoucang? @"shopCollected": @"shopCollect"] imageSize:CGSizeMake(Zoom(12), Zoom(11)) maxFont:font];
                    [maker addAttributeStringWithFont:font color:UIColor.whiteColor string:(self.response.data.is_shoucang? @" 已收藏": @"  收藏")];
                }];
                view.textAlignment = NSTextAlignmentCenter;
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
            view;
        }) withHeight:Zoom(24) width:Zoom(70) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:0 centerY:YES];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:kRBStatusBarHeight + kRBNavigationBarHeight + Zoom(15) bottom:0 left:Zoom(15) right:Zoom(15) centerX:0];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        [view rbSetCornerRadius:Zoom(4)];
        view.backgroundColor = [UIColor colorWithHexString:@"#FFE6BE"];
//        [view h_view_addView:[RanTool imgViewWithMode:0 radius:0 imgName:@"vip4"] withHeight:Zoom(13) width:Zoom(13) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(13) right:0 centerY:YES];
        [view h_view_addView:[RanTool labelWithFontSize:Zoom(13) weight:2 color:@"#D08537" align:0 text:@"店铺会员等级"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(9) right:0 centerY:0];
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:2 color:@"#FB4241" align:0 text:[NSString stringWithFormat:@"V%@",self.response.data.level]];
            [view addPriority:1];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:Zoom(13) centerY:0];
        view;
    }) withHeight:Zoom(36) width:CGFLOAT_MIN top:Zoom(50) bottom:0 left:Zoom(16) right:Zoom(16) centerX:0];
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        [view view_addView:({
            UILabel *view = UILabel.new;
            view.numberOfLines = 0;
            view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(12)] color:[RBThemeConfig textLightBlackColor] string:self.response.data.content lineSpacing:Zoom(8)];
            }];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(15) bottom:Zoom(15) left:Zoom(15) right:Zoom(15) centerX:0];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(16) right:Zoom(16) centerX:NO];
}

#pragma mark - Network

- (void)getData
{
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"store_id"] = self.id;
    } path:@"han_store_base" post:YES log:YES responseClass:RBShopDetailResponse.class desView:self.view showHud:YES showPlaceHolder:YES sucBlock:^(RBShopDetailResponse *response) {
        weak_self.response = response;
        [weak_self fillData];
    } failBlock:^(RBShopDetailResponse *response) {
        [weak_self.view showTip:response.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Event

- (void)collectBtnTapped
{
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"goodsid"] = self.id;
        dicM[@"type"] = @"3";
    } path:@"han_store_do_collect" post:YES log:YES responseClass:RBResponse.class desView:self.view showHud:YES showPlaceHolder:YES sucBlock:^(RBResponse *response) {
        [weak_self getData];
    } failBlock:^(RBResponse *response) {
        [weak_self.view showTip:response.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Setter

#pragma mark - Getter

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            view;
        });
    }
    return _scrollView;
}

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *view = RBNavigationBar.new;
            view.needGradientView = NO;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            [view.naviBar addBackBtn];
            [view.naviBar view_addView:[RanTool labelWithFontSize:15 weight:2 color:UIColor.whiteColor align:0 text:@"店铺详情"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
            view;
        });
    }
    return _navigationBar;
}

@end
